package net.lahuobao.export.service.impl;

import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.springframework.format.datetime.DateFormatter;
import org.springframework.stereotype.Service;

import net.lahuobao.export.datasoruce.annotation.ExportField;
import net.lahuobao.export.service.tranf.IDateTranf;

@Service("dateTranfService")
public class DateTranfImpl implements IDateTranf {


	/**
	 * 时间翻译工具类
	 * @author Administrator
	 *
	 */
	@Override
	public Object dateTranf(Object o, Field field) {
		String dataType=field.getAnnotation(ExportField.class).dateType();
		PropertyDescriptor propDesc = null;
		Object d=null;
		try {
			propDesc = new PropertyDescriptor(field.getName(),o.getClass());
		} catch (IntrospectionException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		Method methodGet=propDesc.getReadMethod();
		try {
			d = methodGet.invoke(o);
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		SimpleDateFormat df = new SimpleDateFormat(dataType);//设置日期格式
		if(null!=d && !d.equals("")){
			d=df.format(d);
		}
		return d;
	}

}
